
	var hostUrl = "https://apiv2.readerday.com/api/v2/";
	var imgHosturl = "http://img.readerday.com/cover/";
	var imgFaceurl = "http://img.readerday.com/face/";
	var slogenFont = ["蜜读 | 解读全球经典好书","蜜读 | 传播全人类共有的知识和观点","蜜读 | 书,是人生的第一滴蜜","蜜读 | 名师解读,30分钟即可阅读一本书","蜜读 | 留存全书精髓,过滤90%的无效信息","蜜读 | 严选国内外经典好书,告别低质阅读","蜜读 | 帮你化繁为简,降低阅读难度"]
	    
		function payClick(userInfo,type,product_id,isCloseCurrentPage,backFunc) {
		 var reqData={
	      	  "channel":'weixin',
	          "type": type,
	          "openId": userInfo.openId,
	          "unionId": userInfo.unionId,
	          "client_ip":userInfo.ip,
	          "product_id": product_id,
	    };
		  $.ajax({
		      url: hostUrl+"miduwxpay/wxwebsave",
		      type: "post",
		      data:reqData,
		      dataType: "json",
		      success: function (data) {
		          if (data.status == 0) {
		              var att = data.data;
		              pay(att.timeStamp, att.nonceStr, att.package, att.paySign, att.orderno,isCloseCurrentPage,type,backFunc);
		          } else {
		              alert(data.message);
		          }
		      },
		      error: function () {
		          alert("出错了");
		          }
		      });
		  }
		    
		    function pay(timeStamp, nonceStr, package, paySign, orderno,isCloseCurrentPage,type,backFunc) {
		    	
			      wx.chooseWXPay({
		          timestamp: timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
		          nonceStr: '' + nonceStr + '', // 支付签名随机串，不长于 32 位
		          package: '' + package + '', // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
		          signType: 'MD5', // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
		          paySign: '' + paySign + '', // 支付签名
		          success: function (res) {
		          		// 支付成功后的回调函数
		                $.ajax({
		                    url: hostUrl+"miduwxpay/findByNo",
		                    type: "post",
		                    data: {
		                        "orderNo": "" + orderno + ""
		                    },
		                    dataType: "json",
		                    success: function (data) {
		                        if (data.status == 0) {
//		                            var timestamp = new Date().getTime();
									
									if(type==7){
										backFunc();
										return;
									}
									if(isCloseCurrentPage){                //主题包试读页面的购买
										if(window.sessionStorage.getItem("hasSubscribe")=="false"){
											window.sessionStorage.setItem("type","1")     //未关注公众号购买后刷新需要弹出二维码
											history.go(-1);
										}
	                            		history.go(-1);
									}else{
										if(window.sessionStorage.getItem("hasSubscribe")=="false"){
											window.sessionStorage.setItem("type","1")     //未关注公众号购买后刷新需要弹出二维码
											location.reload();
										}
	                            		location.reload();
									}
									//会员支付完成
									
		                        } else {
		                            alert(data.message);
		                        }
		                    }
		                });
		          },
		          cancel: function (res) {
		
		          }
		      });
		 }
	
	function ascli(url){
		var param = url.split("?")[1].split("&");
		param.sort();
		str = param.join("&")+"&key=wwdxreaderwhat0823";
		return url+"&sign="+hex_md5(str).toUpperCase();
	}
	function rand(min,max){
		return parseInt(Math.random()*(max-min))+min;
	}
	function formatSeconds(a) {
	  var hh = parseInt(a/3600);
	  if(hh >0 && hh <10){hh = "0" + hh;}
	  else {
	    hh = '';
	  }
	  var mm = parseInt((a-hh*3600)/60);
	  if(mm<10) mm = "0" + mm;
	  var ss = parseInt((a-hh*3600)%60);
	  if(ss<10) ss = "0" + ss;
	  var length = hh.length?(hh + ":" + mm + ":" + ss):mm + ":" + ss;
	  if(a>0){
	    return length;
	  }else{
	    return "NaN";
	  }
	}
	
	Date.prototype.Format = function(formatStr) {
		var str = formatStr;
		var Week = [ '日', '一', '二', '三', '四', '五', '六' ];
	
		str = str.replace(/yyyy|YYYY/, this.getFullYear());
		str = str.replace(/yy|YY/,(this.getYear() % 100) > 9 ? (this.getYear() % 100).toString() : '0' + (this.getYear() % 100));
	
		str = str.replace(/MM/, (this.getMonth() + 1) > 9 ? (this.getMonth() + 1).toString() : '0' + (this.getMonth() + 1));
		str = str.replace(/M/g, this.getMonth());
	
		str = str.replace(/w|W/g, Week[this.getDay()]);
	
		str = str.replace(/dd|DD/, this.getDate() > 9 ? this.getDate().toString() : '0' + this.getDate());
		str = str.replace(/d|D/g, this.getDate());
	
		str = str.replace(/hh|HH/, this.getHours() > 9 ? this.getHours().toString() : '0' + this.getHours());
		str = str.replace(/h|H/g, this.getHours());
		str = str.replace(/mm/, this.getMinutes() > 9 ? this.getMinutes().toString() : '0' + this.getMinutes());
		str = str.replace(/m/g, this.getMinutes());
	
		str = str.replace(/ss|SS/, this.getSeconds() > 9 ? this.getSeconds().toString() : '0' + this.getSeconds());
		str = str.replace(/s|S/g, this.getSeconds());
	
		return str;
	}
	
	function GetQueryString(name){
	    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
	    var r = window.location.search.substr(1).match(reg);
	    if(r!=null)return  decodeURIComponent(r[2]); return null;
	}
	
	template.defaults.imports.addUrl = function(value){
		if(value==null||value==""){
			return "img/book.png"
		}else{
			return imgHosturl+value
		}
	};
	template.defaults.imports.totalReadCount = function(value){
		if(value !== null){
			value = value.toString();
			if(value.length<=4){
				return value;
			}else{
				value = value/10000;
				return value = value.toFixed(1)+"万"
			}
		}
	};
	template.defaults.imports.topcolor = function(index){
		if(index<3){
			return index+1;
		}else{
			return 4;
		}
	};
	
	template.defaults.imports.addFaceUrl = function(value){
		if(value==""||value==null){
			return "img/book.png"
		}else{
			if(checkURL(value)){
				return value;
			}else{
				return imgFaceurl+value
			}
		}
	};
	
	function checkURL(str) {
	    if (str.match(/(http[s]?|ftp):\/\/[^\/\.]+?\..+\w$/i) == null) {
	        return false
	    }
	    else {
	        return true;
	    }
	}
	// 2单本   1书包
	
	

	function weekTip(text){
	  	$("#warn").html(text).show();
		setTimeout(function(){
			$("#warn").hide();
		},2000)
  }
	
	var Q = Query = {
		getFromURL: function(url,parameter){
			var index = url.indexOf("?");
			if (index != -1) {
				var parameterString = url.substr(index + 1);
				var reg = new RegExp("(^|&)" + parameter + "=([^&]*)(&|$)", "i");
				var r = parameterString.match(reg);
				if (r != null){
					return r[2];
				}
			}
			return null;
		},
		get: function(parameter) {
			if (typeof (parameter) == "undefined" || parameter == "") {
				return null;
			}
			var url = window.location.href;		
			var index = url.indexOf("?");
			if (index != -1) {
				var parameterString = url.substr(index + 1);
				var reg = new RegExp("(^|&)" + parameter + "=([^&]*)(&|$)", "i");
				var r = parameterString.match(reg);
				if (r != null){
					return r[2];
				}
			}
			return null;
		},
		getInt:function(parameter,defaultValue){
			var value = parseInt(this.get(parameter));
			return isNaN(value) ? (typeof(defaultValue) == "undefined" ? 0 : defaultValue) : value;
		},
		getDecoded:function(parameter){
			return this.decode(this.get(parameter));
		},
		decode:function(srcStr){
			if(typeof(srcStr) == "undefined"){return null;}
			return decodeURIComponent(srcStr);
		},
		encode:function(srcStr){
			if(typeof(srcStr) == "undefined"){return null;}
			return encodeURIComponent(srcStr);
		},
		getSymbol:function(url){
			return url.indexOf("?") == -1 ? "?" : "&";
		},
		joinURL:function(url,queryString){
			return url + this.getSymbol(url) + queryString;
		},
		createQueryString:function(obj){
			var a = [];
			for(var p in obj){
				if(typeof(obj[p]) == "function" || obj[p] == null || typeof(obj[p])=="undefined") continue;
				a.push(p + "=" + obj[p]);
			}
			return a.join("&");	
		}
	};
	
	